package com.hntest.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hntest.entity.LoginInfo;
import com.hntest.entity.Pager;
import com.hntest.entity.RealAuth;
import com.hntest.entity.VedioAuth;
import com.hntest.service.LoginService;
import com.hntest.service.RealAuthService;
import com.hntest.service.VedioAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller("vedioAuthController")
public class VedioAuthController {

    @Autowired
    private VedioAuthService vedioAuthService;

    @Autowired
    private LoginService loginService;

    @RequestMapping(value = "/admin/vedioAuthSelect",method = {RequestMethod.GET,RequestMethod.POST})
    public String select(Pager pager, VedioAuth vedioAuth, ModelMap modelMap){
        List<VedioAuth> list = vedioAuthService.getListByPage(pager,vedioAuth);
        modelMap.put("list",list);
        modelMap.put("pager",pager);
        modelMap.put("vedioAuth",vedioAuth);
        return "admin/selectVedioAuth";
    }


    @RequestMapping(value = "/admin/vedioAuthdoInsert",method = {RequestMethod.GET,RequestMethod.POST},produces= {"application/JSON;charset=utf-8"})
    @ResponseBody
    public Object doInsertVedioAuth( VedioAuth vedioAuth,LoginInfo loginInfo,HttpServletRequest request){
        HttpSession session = request.getSession(true);
        LoginInfo adminUser = (LoginInfo) session.getAttribute("adminUser");
        vedioAuth.setAuditor(adminUser);
        System.out.println(loginInfo.getUsername());
        List<LoginInfo> loginInfos = loginService.selectLogin(loginInfo.getUsername());
        vedioAuth.setApplier(loginInfos.get(0));
        int n = vedioAuthService.insertVedioAuth(vedioAuth);
        JSONObject jsonObject = new JSONObject();
        if (n>0){
            jsonObject.put("success",true);
            jsonObject.put("msg","审核完成");
        }else{
            jsonObject.put("success",false);
            jsonObject.put("msg","系统异常，审核出错");
        }
       // return "admin/insertRealAuth";
        return JSON.toJSONString(jsonObject);
    }

}
